//
//  OGWindowController.m
//  OsteoGest
//
//  Created by Pierre de FIlippis on 6/25/07.
//  Copyright 2007 . All rights reserved.
//

#import "OGWindowController.h"
#import "OGTestWindow.h"

#import "Customer.h"

#define MIN_SPLITTER_POSITION	140.0
#define MAX_SPLITTER_POSITION	180.0

@implementation OGWindowController

- (id)init
{
	self = [super initWithWindowNibName: @"OGWindowController"];
	if (self)
	{
		[self window];
	}
	return self;
}

- (void) dealloc
{
	//[rootItem dealloc];
	[super dealloc];
}


- (void)awakeFromNib
{
	[_customers bind:@"arrangedObjects" toObject:_column withKeyPath:@"customers" options:nil];
}

- (void)windowDidLoad
{
	[_column reloadData];
	[super windowDidLoad];
}

#pragma mark SPLIT VIEW DELEGATE METHODS

- (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset
{
	return MIN_SPLITTER_POSITION;
}

- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset
{
	return MAX_SPLITTER_POSITION;
}

- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview
{
	//NSLog(@"in canCollapseSplitView");
	return NO;
}

- (float)splitView:(NSSplitView *)sender constrainSplitPosition:(float)proposedPosition ofSubviewAt:(int)offset
{
	//NSLog(@"In constrain split position");
	return proposedPosition;
}

- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
{
	NSView *left = [[sender subviews] objectAtIndex:0];
	NSView *right = [[sender subviews] objectAtIndex:1];
	float dividerThickness = [sender dividerThickness];
	NSRect newFrame = [sender frame];
	NSRect leftFrame = [left frame];
	NSRect rightFrame = [right frame];
	
	leftFrame.size.height = newFrame.size.height;
	
	rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness;
	rightFrame.size.height = newFrame.size.height;
	rightFrame.origin.x = leftFrame.size.width + dividerThickness;
	[left setFrame:leftFrame];
	[right setFrame:rightFrame];
}

@end
